#include<bits/stdc++.h>
using namespace std;
long long t,n,a[200005],b[200005],vis[2],maxn;
int main() {
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    scanf("%lld",&t);
    while (t--) {
        scanf("%lld",&n);
        maxn=0;
        for (long long i=0;i<n;i++) scanf("%lld",&a[i]);
        for (long long i=0;i<(1<<n);i++) {
            vis[0]=vis[1]=0;
            long long sum=0;
            for (long long j=0;j<n;j++) {
                if (vis[(i>>j)&1]==a[j]) sum+=a[j];
                vis[(i>>j)&1]=a[j];
            }
            maxn=max(maxn,sum);
        }
        printf("%lld\n",maxn);
    }
    return 0;
}